package com.ruoyi.packet.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.packet.domain.Packet;
import com.ruoyi.packet.service.IPacketService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 套餐管理Controller
 * 
 * @author fq
 * @date 2025-01-08
 */
@RestController
@RequestMapping("/packet/packet")
public class PacketController extends BaseController
{
    @Autowired
     private IPacketService packetService;


    /**
     * 查询套餐管理列表
     */
    @PreAuthorize("@ss.hasPermi('packet:packet:list')")
    @GetMapping("/list")
    public TableDataInfo list(Packet packet)
    {
        startPage();
        List<Packet> list = packetService.selectPacketList(packet);
        return getDataTable(list);
    }

    /**
     * 导出套餐管理列表
     */
    @PreAuthorize("@ss.hasPermi('packet:packet:export')")
    @Log(title = "套餐管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Packet packet)
    {
        List<Packet> list = packetService.selectPacketList(packet);
        ExcelUtil<Packet> util = new ExcelUtil<Packet>(Packet.class);
        util.exportExcel(response, list, "套餐管理数据");
    }

    /**
     * 获取套餐管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('packet:packet:query')")
    @GetMapping(value = "/{packetId}")
    public AjaxResult getInfo(@PathVariable("packetId") Long packetId)
    {
        return success(packetService.selectPacketByPacketId(packetId));
    }

    /**
     * 新增套餐管理
     */
    @PreAuthorize("@ss.hasPermi('packet:packet:add')")
    @Log(title = "套餐管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Packet packet)
    {
        return toAjax(packetService.insertPacket(packet));
    }

    /**
     * 修改套餐管理
     */
    @PreAuthorize("@ss.hasPermi('packet:packet:edit')")
    @Log(title = "套餐管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Packet packet)
    {
        return toAjax(packetService.updatePacket(packet));
    }

    /**
     * 删除套餐管理
     */
    @PreAuthorize("@ss.hasPermi('packet:packet:remove')")
    @Log(title = "套餐管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{packetIds}")
    public AjaxResult remove(@PathVariable Long[] packetIds)
    {
        return toAjax(packetService.deletePacketByPacketIds(packetIds));
    }

}
